Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ansible role for GCP #1

Merged
merged 1 commit into from
Aug 9, 2022
Merged

Conversation

avery-blanchard
Copy link
Contributor

Create ansible role for deploying Keylime against a vTPM in the google cloud environment. @lkatalin

Copy link
Member

@mpeters mpeters left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not seeing anything in here that's GCP specific. There are new additions for the rust agent and dependencies, but it's very similar to the existing ansible-keylime project.

Are there other planned additions that are GCP specific that are coming later?

name: libselinux-python3
state: present
roles:
- keylime-gcp
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a new line at the end of the files? It's a pretty common thing to require and most code editors have some setting to enable it if it's not the default.

For details on the Rust agent, please consult the [repository](https://github.com/keylime/rust-keylime).

## Usage
Run the playbook against your target remote host(s). Note: the hosts must have the vTPM enabled in the Google Cloud Console.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A cooler next step would be to have this playbook actually create the host(s) in GCP with all of the right settings (OS, image, vTPM, etc). It could have some parameters passed on the cmd line to override some defaults (like compute size, storage size, etc). And since almost all real world scenarios don't have the agent and the server side components (verifier, registrar, etc) running on the same host, it could create a couple of hosts, say 1 where the agent is running and 1 where the server side components are running.

I've done these kinds of playbooks before in ansible for AWS, so I'm making an assumption that they can also work for GCP.

@avery-blanchard avery-blanchard force-pushed the ansible-gcp branch 2 times, most recently from 8ce3eea to cabaaf4 Compare July 13, 2022 18:07
Copy link
Collaborator

@lkatalin lkatalin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did a quick test and ran into an error! Luckily for us, I am the perfect naive user here so a problem I run into is likely to be found by others as well. It's probably something I'm doing wrong, I can help troubleshoot if it's useful.

Also was wondering how does one run the tests? Can that go in the README also?

README.md Outdated
# keylime-cloud-environments
Setup instructions and scripts for running Keylime in cloud environments
# Keylime Cloud Environments
Setup instructions and scripts for running [Keylime](https://github.com/keylime/keylime) in cloud environments.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would add a line here that says something like: each cloud environment is located in a separate directory. Navigate to these and follow the instructions in the README. (maybe with links)

`$ pip3 install requests google-auth`
2. [Create a GCP service account](https://developers.google.com/identity/protocols/oauth2/service-account#creatinganaccount) for ansible's use.
3. [Create and download keys linked to this service account](https://support.google.com/cloud/answer/6158849?hl=en&ref_topic=6262490#serviceaccounts&zippy=%2Cservice-accounts)
4. Add path to ssh key to ansible config (/etc/ansible/ansible.conf) \
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
4. Add path to ssh key to ansible config (/etc/ansible/ansible.conf) \
4. Add path to ssh key to ansible config (`/etc/ansible/ansible.conf`) \

Comment on lines 19 to 20
[defaults] \
private_key_file = /home/user/my_key
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would suggest putting this in a code block

1. Install dependecies for the Ansible - GCP module
`$ pip3 install requests google-auth`
2. [Create a GCP service account](https://developers.google.com/identity/protocols/oauth2/service-account#creatinganaccount) for ansible's use.
3. [Create and download keys linked to this service account](https://support.google.com/cloud/answer/6158849?hl=en&ref_topic=6262490#serviceaccounts&zippy=%2Cservice-accounts)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"Choose whether to download the service account's public/private key as a standard P12 file, or as a JSON file that can be loaded by a Google API client library." which one here? I ended up using P12

## Configuration
1. Install dependecies for the Ansible - GCP module
`$ pip3 install requests google-auth`
2. [Create a GCP service account](https://developers.google.com/identity/protocols/oauth2/service-account#creatinganaccount) for ansible's use.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might be good to add a step about using an existing project or creating a new one, because GCP forces you to do this before you can create the service account. Or just change this step to "create/use a project in your GCP account and then [create a GCP service account]"


## Configuration
1. Install dependecies for the Ansible - GCP module
`$ pip3 install requests google-auth`
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe add that openssl is required / helpful

`$ export GCP_PROJECT="<name of GCP project>"` \
`$ export GCP_CRED_KIND="serviceaccount"`\
`$ export GCP_CRED_FILE="<path to your service account key file>"` \
`$ export GCP_ZONE="<zone for GCP instance>"` \
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it'd be nice to suggest a default zone and/or link to the GCP zones page

`$ export GCP_CRED_KIND="serviceaccount"`\
`$ export GCP_CRED_FILE="<path to your service account key file>"` \
`$ export GCP_ZONE="<zone for GCP instance>"` \
`$ export GCP_REGION="<region for GCP instance>"`
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same for this


## Configuration
1. Install dependecies for the Ansible - GCP module
`$ pip3 install requests google-auth`
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd say ansible is also a dependency!

Run the playbook to create and set up an instance.

```bash
ansible-playbook playbook.yml
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I got this error:

[lily@localhost keylime-ansible-gcp]$ ansible-playbook playbook.yml
[WARNING]: provided hosts list is empty, only localhost is available. Note that the implicit localhost does not match 'all'
ERROR! couldn't resolve module/action 'google.cloud.gcp_compute_disk'. This often indicates a misspelling, missing collection, or incorrect module path.

The error appears to be in '/home/lily/Repos/keylime-cloud-environments/keylime-ansible-gcp/roles/create-gcp/tasks/gcp.yml': line 1, column 3, but may
be elsewhere in the file depending on the exact syntax problem.

The offending line appears to be:

- name: Create disk mapped from Fedora image
  ^ here

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks like it may be the problem but I'm not sure what to enter for hostname / username, do you know?

Copy link
Collaborator

@lkatalin lkatalin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The playbook seems to work this time in setting up the instance (from my local laptop)!! 💯

Though it does fail on

TASK [Wait to SSH into instance] ***********************************************
fatal: [localhost]: FAILED! => {"changed": false, "elapsed": 105, "msg": "Timeout when waiting for 34.152.62.86:22"}

PLAY RECAP *********************************************************************
localhost                  : ok=5    changed=2    unreachable=0    failed=1    skipped=0    rescued=0    ignored=0   

Maybe it's a network or permissions setting? Should I try from a GCP instance?

keylime-ansible-gcp/README.md Outdated Show resolved Hide resolved
keylime-ansible-gcp/README.md Show resolved Hide resolved
keylime-ansible-gcp/README.md Outdated Show resolved Hide resolved
keylime-ansible-gcp/README.md Outdated Show resolved Hide resolved
keylime-ansible-gcp/README.md Outdated Show resolved Hide resolved
keylime-ansible-gcp/README.md Outdated Show resolved Hide resolved
keylime-ansible-gcp/set_env_var.sh Show resolved Hide resolved
Copy link
Collaborator

@lkatalin lkatalin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is working for me! Thanks for all the debugging and hard work, @avery-blanchard !

@mpeters Should we merge? Or would you like to try it? There is one step where a script parses the JSON file downloaded from GCP (this file includes a private key) and the script emits a warning before doing so. I think this should be okay but let me know if you think otherwise.

@mpeters
Copy link
Member

mpeters commented Jul 29, 2022

I'll give this a spin on Monday and then we can merge it if there isn't anything big.

keylime-ansible-gcp/README.md Outdated Show resolved Hide resolved
keylime-ansible-gcp/README.md Outdated Show resolved Hide resolved
keylime-ansible-gcp/README.md Outdated Show resolved Hide resolved
keylime-ansible-gcp/playbook.yml Outdated Show resolved Hide resolved
keylime-ansible-gcp/roles/create-gcp/handlers/main.yml Outdated Show resolved Hide resolved
keylime-ansible-gcp/roles/create-gcp/defaults/main.yml Outdated Show resolved Hide resolved
keylime-ansible-gcp/roles/create-gcp/meta/main.yml Outdated Show resolved Hide resolved
keylime-ansible-gcp/roles/keylime-gcp/defaults/main.yml Outdated Show resolved Hide resolved
Copy link
Member

@mpeters mpeters left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's looking good, but a couple of points:

  1. If, as I suspect, the create-gcp role only holds tasks, then it doesn't need to be a role at all. It can just be a playbook of tasks. Not everything has to be a role and in fact, simple groups of tasks are better off as just a playbook instead of a role.

  2. You moved a lot of stuff into the other ansible keylime project but I'd like to it better connected. The coolest would be to have some way to automatically apply that other role to these newly created instances. But if that seems too unwieldy, maybe just making it more explicit about how you would create an inventory file, checkout the project and run the playbooks in there.

@@ -0,0 +1 @@
- include: gcp.yml
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the reason for splitting the tasks out into an include instead of directly in the main.yml?

@@ -0,0 +1,4 @@
---
# Section for vars
shell_profiles:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see this shell_profiles variable used anywhere.

@@ -0,0 +1 @@
localhost
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the purpose of this /tests directory and this inventory file?

@mpeters
Copy link
Member

mpeters commented Aug 9, 2022

@avery-blanchard can you squash all of these commits into a single commit? That makes it easier to manage and is typical for most projects. There's no reason to keep all of the back and forth and fixes in separate commits and we'll have a nice clean history.

Signed-off-by: Avery Blanchard <[email protected]>
@mpeters mpeters merged commit 7b9f0d9 into keylime:main Aug 9, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants